<!DOCTYPE html>
<html lang="zh-Hans-CN">
<head>
  <meta charset="UTF-8">
  <title>透视投影照相机</title>
</head>
<body onload="init()">
<script src="three.min.js"></script>
<script>
  /* 参数
   -----------------------------------------------------------------

   THREE.PerspectiveCamera(fov, aspect, near, far)

   - fov 是视景体竖直方向上的张角（是角度制而非弧度制）
   - aspect等于width / height，是照相机水平方向和竖直方向长度的比值，通常设为Canvas的横纵比例
   - near和far分别是照相机到视景体最近、最远的距离，均为正值，且far应大于near

   -----------------------------------------------------------------
   */

  function init() {
    let renderer = new THREE.WebGLRenderer();
    renderer.setSize(400, 300);
    document.body.appendChild(renderer.domElement);
    renderer.setClearColor(0x000000)

    let scene = new THREE.Scene();

    let camera = new THREE.PerspectiveCamera(40, 400 / 300, 1, 10)
    camera.position.set(1.8, 4, 5);
    camera.lookAt(new THREE.Vector3(0, 0, 0));
    scene.add(camera);

    let cube = new THREE.Mesh(new THREE.CubeGeometry(1, 1, 1),
        new THREE.MeshBasicMaterial({
          color: 0xff0000,
          wireframe: true
        })
    );
    scene.add(cube);

    renderer.render(scene, camera);
  }
</script>
</body>
</html>